class StudentMetaclass(type):
    # 元类会自动将type里的参数作为自己的参数传入
    def __new__(self, class_name, class_parents, class_attr):
        # class_name是类名称,class_parents是父类，class_attr是类的属性
        print(class_attr)
        b = {}

        def test(self):
            print(class_name)

        for key, value in class_attr.items():
            # 遍历类属性里的名称和值
            # 排除一下，不然无法实例了
            if key[0] == '_':
                b[key] = value
                continue
            print(key, ':', value)
            b[key.upper()] = value
            # 把名称变成大写
        b['test'] = test
        print(b)
        return type.__new__(self, class_name, class_parents, b)
        # 用type这个元类来创建类，这个b里的名称已经大写了


class Student(object, metaclass=StudentMetaclass):
    # __metaclass__ = StudentMetaclass   # python2 的写法

    def __init__(self, name):
        self.name = name

    def get_name(self):
        return self.name

    def __str__(self):
        return '<%s:%s>' % (self.__class__.__name__, self.name)
    __repr__ = __str__


s1 = Student('王楠')
print(s1.GET_NAME())
s1.test()
print(s1)
print(Student)
